#include <bits/stdc++.h>

#include <atcoder/all>
#define LL long long
using namespace std;
using namespace atcoder;

const int kMaxV = 5e5 + 10;
const int kMod = 998244353;

modint998244353 cnta[kMaxV], cntb[kMaxV];
modint998244353 fac[kMaxV], inv_fac[kMaxV];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;

  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a;

    cin >> a;
    cnta[a]++;
  }
  for (int j = 0; j < m; j++) {
    int b;

    cin >> b;
    cntb[b]++;
  }
  fac[0] = 1;
  for (int i = 1; i < kMaxV; i++) {
    fac[i] = fac[i - 1] * i;
  }
  inv_fac[kMaxV - 1] = fac[kMaxV - 1].inv();
  for (int i = kMaxV - 2; i >= 0; i--) {
    inv_fac[i] = inv_fac[i + 1] * (i + 1);
  }

  vector<modint998244353> b1(kMaxV), b2(kMaxV);
  for (int i = 0; i < kMaxV; i++) {
    b1[i] = cntb[i] * inv_fac[i];
    b2[i] = inv_fac[i];
  }
  vector<modint998244353> c = convolution(b1, b2);

  modint998244353 ans = 0;
  for (int i = 0; i < kMaxV; i++) {
    ans += cnta[i] * fac[i] * c[i];
  }
  cout << ans.val() << "\n";
  return 0;
}
